// eslint-disable-next-line no-unused-vars
import axios from 'axios';

export class Style {
  store
  constructor(store) {
    this.store = store
  }
  async addNewStyle (newStyle) {
    var styleElement = document.getElementById('low_code');

    if (!styleElement) {
      styleElement = document.createElement('style');
      styleElement.type = 'text/css';
      styleElement.id = 'low_code';
      document.getElementsByTagName('head')[0].appendChild(styleElement);
    }
    styleElement.innerText = ''
    let css = await this.parseSass(newStyle)
    styleElement.appendChild(document.createTextNode(css));
  }
  async parseSass (newStyle) {
    let resultCss = await axios({
      method: "post",
      url: "https://api.sassmeister.com/compile",
      data: {
        compiler: "dart-sass/1.32.12",
        input: newStyle,
        outputStyle: "expanded",
        syntax: "SCSS"
      }
    })
    return resultCss.data.css

  }

}